//实时曲线图
var spline_list=[];
var splineChart;
//实时图表
    $(document).ready(function () {
        Highcharts.setOptions({
            global: {
                useUTC: false
            }
        });
        splineChart=Highcharts.chart('shishi',{
            chart: {
                type: 'spline',
                animation: Highcharts.svg, // don't animate in old IE
                marginRight: 10,
                events: {
                    load: function () {
                    }
                }
            },
            title: {
                text: '实时曲线图'
            },
            xAxis: {
                type: 'datetime',
                tickPixelInterval: 150
            },
            yAxis: {
                title: {
                    text: 'Value'
                },
                plotLines: [{
                    value: 0,
                    width: 1,
                    color: '#808080'
                }]
            },
            tooltip: {
                formatter: function () {
                    return '<b>' + this.series.name + '</b><br/>' +
                        Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x) + '<br/>' +
                        Highcharts.numberFormat(this.y, 2);
                }
            },
            legend: {
                enabled: false
            },
            exporting: {
                enabled: false
            },
            series: [{
                name: 'Random data',
                data: [{x: (new Date()).getTime(),
                    y: 0
                }]
            }]
        });
       // setSpline(5);
    });
   
function setSpline(y,status){
	if(spline_list.length==0){
		for(var i=1;i<=8;i++){
			spline_list.push({x: (new Date()).getTime()-(8-i)*1000,
                y: y
              });
		}
		splineChart.series[0].setData(spline_list);
	}
	if(spline_list.length>=8&&status==1){
		spline_list.push({x: (new Date()).getTime(),
            y: y
          });
		spline_list=spline_list.slice(1, 8);
		splineChart.series[0].setData(spline_list);
	}
       
}

function reset(){
	spline_list=[];
	var value=$("#select_parameter").index($("#select_parameter option:selected"));
	var name="";
	if(value=="vehicle_speed"){
		name="车速";
	}else if(value=="total_vol"){
		name="电池总电压";
	}else if(value=="total_cur"){
		name="电池总电流";
	}else if(value=="soc"){
		name="SOC";
	}else if(value=="motor_speed"){
		name="电机转速";
	}else if(value=="motor_nm"){
		name="电机扭矩";
	}else if(value=="motor_temp"){
		name="电机温度";
	}
	splineChart.series[0].setName(name);
}

//第二个  柱状图

$(function () {
    $('#er1').highcharts({
        chart: {
            type: 'column'
        },
        title: {
            text: ''
        },
        subtitle: {
            text: '电池单体电压'
        },
        xAxis: {
            categories: [
                'Jan',
                'Feb',
                'Mar',
                'Apr',
                'May',
                'Jun',
                'Jul',
                'Aug',
                'Sep',
                'Oct',
                'Nov',
                'Dec'
            ],
            crosshair: true
        },
        yAxis: {
            min: 0,
            title: {
                text: 'Rainfall (mm)'
            }
        },
        tooltip: {
            headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
            pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
            '<td style="padding:0"><b>{point.y:.1f} mm</b></td></tr>',
            footerFormat: '</table>',
            shared: true,
            useHTML: true
        },
        plotOptions: {
            column: {
                colorByPoint:true
            }
        },
        series: [{
            name: 'Tokyo',
            //colorByPoint:true,  或者直接写在这里
            data: [
					{'color':'red','y':11},
					{'color':'green','y':20},
					{'color':'blue','y':40},
					{'color':'green','y':20},
					{'color':'blue','y':50},
					{'color':'green','y':20},
					]
        }]
    });
});



$(function () {
    $('#er2').highcharts({
        chart: {
            type: 'column'
        },
        title: {
            text: ''
        },
        subtitle: {
            text: '电池探针温度'
        },
        xAxis: {
            categories: [
                'Jan',
                'Feb',
                'Mar',
                'Apr',
                'May',
                'Jun',
                'Jul',
                'Aug',
                'Sep',
                'Oct',
                'Nov',
                'Dec'
            ],
            crosshair: true
        },
        yAxis: {
            min: 0,
            title: {
                text: 'Rainfall (mm)'
            }
        },
        tooltip: {
            headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
            pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
            '<td style="padding:0"><b>{point.y:.1f} mm</b></td></tr>',
            footerFormat: '</table>',
            shared: true,
            useHTML: true
        },
        plotOptions: {
            column: {
                colorByPoint:true
            }
        },
        series: [{
            name: 'Tokyo',
            //colorByPoint:true,  或者直接写在这里
            data: [
					{'color':'red','y':11},
					{'color':'green','y':20},
					{'color':'blue','y':40},
					{'color':'green','y':20},
					{'color':'blue','y':50},
					{'color':'green','y':20},
					]
        }]
    });
});